package y_2025.m03.d21.懒汉模式;

public class Main {
    public static void main(String[] args) {
        Cat cat = Cat.getInstance();
        System.out.println("cat = " + cat);
        Cat cat2 = Cat.getInstance();
        System.out.println("cat2 = " + cat2);
    }
}

class Cat {
    private int age;
    private static Cat cat;
    private Cat(int age) {
        this.age = age;
    }
    public static Cat getInstance() {
        if (cat == null) {
            cat = new Cat(1);
        }
        return cat;
    }
    public int getAge() {
        return age;
    }

    @Override
    public String toString() {
        return "Cat{" +
                "age=" + age +
                '}';
    }
}